package com.example.application1.Adapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.application1.Entity.NewslistDTOXX;
import com.example.application1.R;

import java.util.List;

public class weatherAdapter extends RecyclerView.Adapter<weatherAdapter.weatherHolder> {

    private Context context;
    private List<NewslistDTOXX> weatherList;

    public weatherAdapter(Context context,List<NewslistDTOXX> weatherList) {
        this.context=context;
        this.weatherList=weatherList;
    }

    @NonNull
    @Override
    public weatherAdapter.weatherHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new weatherHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.weather_item,parent,false));
    }

    @Override
    public void onBindViewHolder(@NonNull weatherAdapter.weatherHolder holder, int position) {
       holder.temp1.setText(weatherList.get(position).getLowest()+"~"+weatherList.get(position).getHighest());
       holder.week.setText(weatherList.get(position).getWeek());
       holder.weather1.setText(weatherList.get(position).getWeather());
    }

    @Override
    public int getItemCount() {
        return weatherList==null?0:weatherList.size();
    }

    public  void refresh(List<NewslistDTOXX> weatherList){
//      对适配器刷新
       this.weatherList=weatherList;
        notifyDataSetChanged();
        Log.d("lcj","notifyDataSetChanged");
    }

    public class weatherHolder extends RecyclerView.ViewHolder{
        TextView weather1;
        TextView week;
        TextView temp1;
        public weatherHolder(@NonNull View itemView) {
            super(itemView);
             weather1=itemView.findViewById(R.id.weather);
             week=itemView.findViewById(R.id.week);
             temp1=itemView.findViewById(R.id.temp1);
        }
    }
}
